package com.gxa.service.shezhiservice.Impl;

import com.gxa.common.R;
import com.gxa.mapper.shezhimapper.ShouRuType46Mapper;
import com.gxa.pojo.ShouRuType;
import com.gxa.service.shezhiservice.ShangPinType46Service;
import com.gxa.service.shezhiservice.ShouRuType46Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service

public class ShouRuType46ServiceImpl implements ShouRuType46Service {
    @Autowired
    private ShouRuType46Mapper shouRuType46Mapper;
    @Override
    public R selectAllShouRuTypeForPage(int page, int size) {
        R r = new R();
        int index = (page - 1)*size;
        List<ShouRuType> shouRuTypes = shouRuType46Mapper.selectAllShouRuTypeForPage(index,size);
        if (shouRuTypes != null){
            r.setCode(200);
            r.setMsg("查询成功！");
            r.setData(shouRuTypes);
        }
        return r;
    }

    @Override
    public R selectShouRuTypeByType(int page, int size, String shouRuType) {
        R r = new R();
        int index = (page - 1)*size;
        List<ShouRuType> ShouRuTypes = shouRuType46Mapper.selectShouRuTypeByType(index,size,shouRuType);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(ShouRuTypes);
        return r;
    }

    @Override
    public R insertShouRuType(ShouRuType shouRu) {
        R r = new R();
        int res =  shouRuType46Mapper.insertShouRuType(shouRu);
        r.setCode(500);
        r.setMsg("新增失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("新增成功");
        }
        return r;
    }

    @Override
    public R updateShouRuTypeById(ShouRuType shouRu) {
        R r = new R();
        int res =  shouRuType46Mapper.updateShouRuTypeById(shouRu);
        r.setCode(500);
        r.setMsg("更新失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("更新成功");
        }
        return r;
    }

    @Override
    public R deleteShouRuTypeById(int id) {
        R r = new R();
        int res = shouRuType46Mapper.deleteShouRuTypeById(id);
        r.setCode(500);
        r.setMsg("删除失败");
        if(res>0)
        {
            r.setCode(200);
            r.setMsg("删除成功");
        }
        return r;
    }
}
